﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System;
using System.Data;
using System.Linq;
using System.Text;
using System.Drawing;
using WMSABL;
using WMSABL.SY;
using WMSAML.SY;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;

namespace ElectronicWMSA.SY
{
    public partial class InitialPwdFrm : Form
    {
        TUsers_Entity entity = new TUsers_Entity();
        TUsers_BLL bll_TUsers = new TUsers_BLL(); 
        public InitialPwdFrm(int uid)
        {
            InitializeComponent();
            if (uid > 0)
            {
                entity = bll_TUsers.GetEntityByID(uid);
                this.txtLoginName.Text = entity.Username;
            }
            else
                this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string newPass = this.txtNewPass.Text.Trim();
            string passAgain = this.txtPassAgain.Text.Trim();

            if (newPass == "")
            {
                this.labShow.Text = "请输入新密码！";
                this.txtNewPass.Focus();
                return;
            }
            if (passAgain == "")
            {
                this.labShow.Text = "请输入确认新密码！";
                this.txtPassAgain.Focus();
                return;
            }
            if (newPass != passAgain)
            {
                this.labShow.Text = "密码不一致！";
                this.txtPassAgain.Focus();
                return;
            }
            if (entity != null)
            {
                entity.password = DesMd5.MD5Encrypt(newPass);
                if (MessageClass.enquire("确定修改密码！") == DialogResult.OK)
                {
                    if (bll_TUsers.Update(entity))
                    {
                        this.labShow.Text = ""; 
                        SystemVariable.AddLogInfo("初始化密码", "用户" + SystemVariable.User_Name + "操作了初始化用户[" + entity.Login_name + "]密码。");
                        this.Close();
                    }
                    else
                    {
                        this.labShow.Text = "失败！";
                    }
                }
                this.labShow.Text = "提示信息！";
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
